<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets a specific external variable by name and optionally filters it</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.filter-input-array.html">filter_input_array</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.filter-list.html">filter_list</a></div>
 <div class="up"><a href="ref.filter.html">Filter 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.filter-input" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">filter_input</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0)</p><p class="refpurpose"><span class="refname">filter_input</span> &mdash; <span class="dc-title">Gets a specific external variable by name and optionally filters it</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.filter-input-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>filter_input</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$variable_name</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$filter</code><span class="initializer"> = FILTER_DEFAULT</span></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$options</code></span>
  ]] )</div>


 </div>

 <div class="refsect1 parameters" id="refsect1-function.filter-input-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">type</code></em></dt>

     <dd>

      <p class="para">
       One of <strong><code>INPUT_GET</code></strong>, <strong><code>INPUT_POST</code></strong>,
       <strong><code>INPUT_COOKIE</code></strong>, <strong><code>INPUT_SERVER</code></strong>, or
       <strong><code>INPUT_ENV</code></strong>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">variable_name</code></em></dt>

     <dd>

      <p class="para">
       Name of a variable to get.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">filter</code></em></dt>

     <dd>

      <p class="para">
       The ID of the filter to apply. The <a href="filter.filters.html" class="xref">Types of filters</a>
       manual page lists the available filters.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">options</code></em></dt>

     <dd>

      <p class="para">
       Associative array of options or bitwise disjunction of flags. If filter
       accepts options, flags can be provided in &quot;flags&quot; field of array.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.filter-input-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Value of the requested variable on success, <strong><code>FALSE</code></strong> if the filter fails,
   or <strong><code>NULL</code></strong> if the <em><code class="parameter">variable_name</code></em> variable is not set.
   If the flag <strong><code>FILTER_NULL_ON_FAILURE</code></strong> is used, it
   returns <strong><code>FALSE</code></strong> if the variable is not set and <strong><code>NULL</code></strong> if the filter fails.
   </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.filter-input-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4994">
    <p><strong>Example #1 A <span class="function"><strong>filter_input()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$search_html&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">filter_input</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_GET</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'search'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILTER_SANITIZE_SPECIAL_CHARS</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$search_url&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">filter_input</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_GET</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'search'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILTER_SANITIZE_ENCODED</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"You&nbsp;have&nbsp;searched&nbsp;for&nbsp;</span><span style="color: #0000BB">$search_html</span><span style="color: #DD0000">.\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">"&lt;a&nbsp;href='?search=</span><span style="color: #0000BB">$search_url</span><span style="color: #DD0000">'&gt;Search&nbsp;again.&lt;/a&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
You have searched for Me &amp;#38; son.
&lt;a href=&#039;?search=Me%20%26%20son&#039;&gt;Search again.&lt;/a&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.filter-input-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.filter-var.html" class="function" rel="rdfs-seeAlso">filter_var()</a> - Filters a variable with a specified filter</span></li>
    <li class="member"><span class="function"><a href="function.filter-input-array.html" class="function" rel="rdfs-seeAlso">filter_input_array()</a> - Gets external variables and optionally filters them</span></li>
    <li class="member"><span class="function"><a href="function.filter-var-array.html" class="function" rel="rdfs-seeAlso">filter_var_array()</a> - Gets multiple variables and optionally filters them</span></li>
    <li class="member"><a href="filter.filters.html" class="xref">Types of filters</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.filter-input-array.html">filter_input_array</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.filter-list.html">filter_list</a></div>
 <div class="up"><a href="ref.filter.html">Filter 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
